package com.valuegroup.smarttodo.util;


import android.content.Context;
import android.content.DialogInterface;
import android.widget.Toast;

import com.valuegroup.smarttodo.R;

import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;


public class AlertUtils {
    public static void showToast(Context context, String message) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    public static void showToast(Context context, @StringRes int message) {
        showToast(context, context.getString(message));
    }

    public static void showNetworkUnavailable(Context context) {
        showToast(context, R.string.network_is_unavailable);
    }

    public static void showNetworkError(Context context) {
        showToast(context, R.string.network_error);
    }

    public static void dialog(Context context, String msg, String positiveBtnName, String ngativeBtnName, DialogInterface.OnClickListener listenerPositive, DialogInterface.OnClickListener listenerNegative) {
        new AlertDialog.Builder(context)
                .setTitle(context.getResources().getString(R.string.alt_are_you_sure))
                .setMessage(msg)
                .setPositiveButton(positiveBtnName, listenerPositive)
                .setNegativeButton(ngativeBtnName, listenerNegative)
                .show();
    }

    public static void dialog(Context context, int msg, int positiveBtnName, int ngativeBtnName, DialogInterface.OnClickListener listenerPositive, DialogInterface.OnClickListener listenerNegative) {
        new AlertDialog.Builder(context)
                .setTitle(context.getResources().getString(R.string.alt_are_you_sure))
                .setMessage(context.getResources().getString(msg))
                .setPositiveButton(context.getResources().getString(positiveBtnName), listenerPositive)
                .setNegativeButton(context.getResources().getString(ngativeBtnName), listenerNegative)
                .show();
    }

    public static void removeJoinDialog(Context context, String msg, DialogInterface.OnClickListener listener) {
        new AlertDialog.Builder(context)
                .setTitle(context.getResources().getString(R.string.alt_are_you_sure))
                .setMessage(msg)
                .setPositiveButton(context.getResources().getString(R.string.op_remove), listener)
                .setNegativeButton(context.getResources().getString(R.string.op_cancel), null)
                .show();
    }

    public static void delOrderDialog(Context context, String msg, DialogInterface.OnClickListener listener) {
        new AlertDialog.Builder(context)
                .setTitle(context.getResources().getString(R.string.alt_are_you_sure))
                .setMessage(msg)
                .setPositiveButton(context.getResources().getString(R.string.op_delete), listener)
                .setNegativeButton(context.getResources().getString(R.string.op_cancel), null)
                .show();
    }

    public static void changeHabitRuleDialog(Context context, String msg, DialogInterface.OnClickListener listener) {
        new AlertDialog.Builder(context)
                .setTitle(context.getResources().getString(R.string.alt_are_you_sure))
                .setMessage(msg)
                .setPositiveButton(context.getResources().getString(R.string.op_determine), listener)
                .setNegativeButton(context.getResources().getString(R.string.op_cancel), null)
                .show();
    }


    public static void tomatoDialog(Context context, DialogInterface.OnClickListener listener) {
        new AlertDialog.Builder(context)
                .setTitle(context.getResources().getString(R.string.alt_tomato_title))
                .setMessage(context.getResources().getString(R.string.alt_tomato))
                .setPositiveButton(context.getResources().getString(R.string.op_determine), listener)
                .setNegativeButton(context.getResources().getString(R.string.op_cancel), null)
                .show();
    }


    public static void delDialog(Context context, String name, DialogInterface.OnClickListener listener) {
        new AlertDialog.Builder(context)
                .setTitle(context.getResources().getString(R.string.alt_are_you_sure))
                .setMessage(String.format(context.getResources().getString(R.string.alt_del), name))
                .setPositiveButton(context.getResources().getString(R.string.op_delete), listener)
                .setNegativeButton(context.getResources().getString(R.string.op_cancel), null)
                .show();
    }

    public static void delDialog(Context context, int stringId, DialogInterface.OnClickListener listener) {
        delDialog(context, context.getResources().getString(stringId), listener);
    }
}
